package zjh_20230330;

import java.io.*;
import java.nio.charset.Charset;

public class Demo02 {
    public static void main(String[] args) {
        File file = new File("D:\\kaifamiao\\io-text\\text1-up.txt");
        try (FileOutputStream fileOutputStream = new FileOutputStream(file);
             OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "gbk");
             BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);) {

            bufferedWriter.write("我的编码是GBK");

            bufferedWriter.newLine();

            bufferedWriter.write("不是UTF-8了！你瞅瞅");

            System.out.println("写入完成");
        } catch (FileNotFoundException e) {
            throw new RuntimeException("没找到文件，去检查文件路径对不");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("转编码失败");
        } catch (IOException e) {
            throw new RuntimeException("写入失败");
        }
    }
}
